﻿#ifndef SerialPinch_H
#define SerialPinch_H

#include <QDebug>
#include <QObject>
#include <QSerialPort>
#include <QVariantMap>
#include <string>
#include "RobotCmdNode.hpp"

class Commander;

struct PeelCmd {
    PeelCmd()
    {
        memset(m_buff, 0, 8);
        m_strCmdName = "";
    }
    quint8 m_buff[8];
    QString m_strCmdName;
};

class SerialPeel : public QObject {
    Q_OBJECT
public:
    explicit SerialPeel(int argc, char** argv, QObject* parent = nullptr);
    ~SerialPeel();

public:
    void setCom(const std::string& comName);

    void closeCom();

    void call_cmd(const std::string& cmdName);

private slots:

    void openCom();

    void onReadReady();

    void reset();

    void pinch();

    void loose();

    void stop();

    void startPeel(int nCm = 10);

    void stopPeel();

private:
    void rosSpinThread();
    void write(unsigned char* data, int len);

private:
    QSerialPort* m_com;
    int argc_;
    char** argv_;
    std::shared_ptr<RobotCmdNode> m_robotCmdNode;
    std::thread m_ros_spin_thread;

    Commander* m_cmder;
};

#endif  // SerialPinch_H
